﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MMITCore.TransactionActions;
using Moq;
using MMITDomain.Abstract;
using MMITDomain.Entities;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.Common;

namespace MMITUnitTests.Core.TransactionActions
{
    [TestClass]
    public class ActionsUnitTests
    {
        private  IVoucherRepository mockVoucherRepo;
        private Actions actions;
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestInitialize]
        public void Initialize()
        {
            //Initialize
            IList<Voucher> vouchers = new List<Voucher> { new Voucher { PIN = "38741625968924", SerialNo = "PB000000000196" }, 
                new Voucher{ PIN="36918275414758", SerialNo="PB000000000197"}, new Voucher{ PIN="13895276493514", SerialNo="PB000000000195"}, 
                new Voucher{ PIN="28973461518527", SerialNo="PB000000000194"}, new Voucher{ PIN="25341896726317", SerialNo="PB000000000193"}
            };

            var target  = new Mock<IVoucherRepository>();
            target.Setup(p => p.Vouchers).Returns(vouchers.AsQueryable());

            mockVoucherRepo = target.Object;
            actions = new Actions(mockVoucherRepo);
        }

        [TestMethod]
        public void IsVoucherValid()
        {
            //Arrange
            var expected = new Voucher() { PIN = "25341896726317", SerialNo = "PB000000000193" };

            //Act
            var actual = actions.IsVoucherValid("PB000000000193", "25341896726317");

            //Assert
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(Voucher));
            Assert.AreEqual(actual.PIN, expected.PIN);
        }

        [TestMethod]
        public void GetAccount()
        {
            //Arrange
            int customerId = 1072;

            var expected = new Account() { CustomerId=1072, Name="+2348057323452", AccountTypeId=1, 
                CurrencyId=4, Status=6, AvailableBalance=0.00M, ActualBalance=0.00M};

            //Act
            var actual = actions.GetAccount(customerId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(Account));
            Assert.AreEqual(actual.Name, expected.Name);
        }
    }
}
